<template>
    <!-- 渠道管理 -->
    <div>
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="渠道名称">
                <el-input v-model="Mdate.name" placeholder="渠道名称"></el-input>
            </el-form-item>
            <el-form-item label="归属地">
                <el-input v-model="Mdate.address" placeholder="归属地"></el-input>
            </el-form-item>
            <el-form-item label="联系人">
                <el-input v-model="Mdate.people" placeholder="联系人"></el-input>
            </el-form-item>
               <el-form-item label="渠道负责人" v-if="showUserList">
                <el-select v-model="Mdate.userId" placeholder="销售员" >
            <el-option :label="item.ADMIN_NAME" :value="item.ADMIN_ID" :key="item.ADMIN_ID" v-for="item in userList"></el-option> 
               <el-option label="所有" :value="''"></el-option>         
          </el-select>
            </el-form-item>
            <el-form-item label="时间区间">
                <el-date-picker v-model="Mdate.time" type="daterange" placeholder="选择日期范围">
                </el-date-picker>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span style="line-height: 36px;">渠道列表</span>
                <el-button type="primary" style="float:right" @click="AddOrganization">新增</el-button>
            </div>
            <organization-list  ref='organizationList' @goAddCommunication="goAddCommunication" @goAddCustom="goAddCustom" @goOrganizaitionEditer="goOrganizaitionEditer">
            </organization-list>
        </el-card>
        <el-dialog title="沟通记录添加" :visible.sync="connectionAdd" v-if="connectionAdd">
            <communication-Add :id="id" :type="type" @close="close">
            </communication-Add>
        </el-dialog>
        <el-dialog title="新增客戶" :visible.sync="crmadd" v-if="crmadd">
            <custom-show  :type="'渠道新增'" :OrganizationId="OrganizationId" @close="close">
            </custom-show>
        </el-dialog>
        <el-dialog title="新增渠道" :visible.sync="organizationAdd" v-if="organizationAdd" size="large">
            <organization-show :type="'新增'" @close="close">
            </organization-show>
        </el-dialog>
        <el-dialog title="查看渠道" :visible.sync="organizaitionEditer" v-if="organizaitionEditer" size="large">
            <organization-show :type="'修改'" :Id="OrganizationId" @close="close" @goAddCommunication="goAddCommunication">
            </organization-show>
        </el-dialog>
    </div>
</template>
<script>
import OrganizationList from "@/components/Crm/OrganizationList";
import CommunicationAdd from "@/components/Crm/CommunicationAdd";
import CustomShow from "@/components/Crm/CustomShow";
import OrganizationShow from "@/components/Crm/OrganizationShow";
import api from "@/js/api";
export default {
  data() {
    return {
      userList: [], //用户列表
      daterange: "",
      connectionAdd: false, //渠道新增
      id: "", //沟通记录 客户、渠道id
      type: "", //沟通记录 类型

      crmadd: false,
      oid: "", // 渠道id
      organizationAdd: false,
      organizaitionEditer: false,
      ORGANIZATION_NAME: "",
      listShow: true,
      //OrganizationId 查询用
      OrganizationId: "",
      //多条件查询
      Mdate: {
        name: "",
        address: "",
        people: "",
        time: [],
        userId: ""
      },
      showUserList: false //是否显示uselist
    };
  },
  components: {
    "organization-list": OrganizationList,
    "communication-Add": CommunicationAdd,
    "custom-show": CustomShow,
    "organization-show": OrganizationShow
  },
  methods: {
    onSubmit: function() {

      this.$refs.organizationList.Mselect(this.Mdate);
    },
    AddOrganization: function() {
      this.organizationAdd = true;
    },
    goAddCommunication(data) {
      this.id = data.id;

      this.type = data.type;
      this.connectionAdd = true;
    },
    goAddCustom(oid) {

      this.OrganizationId = oid;
      this.crmadd = true;
    },
    //查看
    goOrganizaitionEditer(id) {
  
      this.OrganizationId = id;
      this.organizaitionEditer = true;
    },
    //关闭弹窗
    close() {
      this.crmadd = false;
      this.connectionAdd = false;
      this.organizationAdd = false;
      this.organizaitionEditer = false;
      this.crmadd = false;
      //更新list
      this.$refs.organizationList.Getdata();
    },
    getUserList() {
      let that = this;
      api.AdminGetList(that, {}, function(msg) {
        that.userList = msg.Result;
      });
    }
  },

  activated() {
    this.crmadd = false;
    this.connectionAdd = false;
    this.getUserList();
    var role = sessionStorage.getItem("userRole");
    if (role == "销售助理" || role == "销售主管") {
      this.showUserList = true;
    }   
  }
};
</script>

